#include <graphics.h>      
#include <conio.h>
int x = 320, y = 320;
void left();
void right();
void up();
void down();

void left(){
	char c = 0;
	for (;; x -= 4) {
		if (x == 0)
			right();
		setcolor(YELLOW);
		setfillcolor(GREEN);
		fillcircle(x, y, 10); 
		Sleep(1);
		setcolor(BLACK);
		setfillcolor(BLACK);
		fillcircle(x, y, 10); 
		
		if (_kbhit())
			c = _getch();
		switch (c) {
		case 'a': left(); break;
		case 'd': right(); break;
		case 'w': up(); break;
		case 's': down(); break;
		case 27: exit(0);
		}
	}
}

void right(){
	char c = 0;
	for (;; x += 4) {
		if (x == 640)
			left();
		setcolor(YELLOW);
		setfillcolor(GREEN);
		fillcircle(x, y, 10);
		Sleep(1);
		setcolor(BLACK);
		setfillcolor(BLACK);
		fillcircle(x, y, 10);

		
		if (_kbhit())
			c = _getch();
		switch (c) {
		case 'a': left(); break;
		case 'd': right(); break;
		case 'w': up(); break;
		case 's': down(); break;
		case 27: exit(0);
		}
	}
}

void up(){
	char c = 0;
	for (;; y -= 4) {
		if (y == 0)
			down();
		setcolor(YELLOW);
		setfillcolor(GREEN);
		fillcircle(x, y, 10);
		Sleep(1);
		setcolor(BLACK);
		setfillcolor(BLACK);
		fillcircle(x, y, 10);

		if (_kbhit())
			c = _getch();
		switch (c) {
		case 'a': left(); break;
		case 'd': right(); break;
		case 'w': up(); break;
		case 's': down(); break;
		case 27: exit(0);
		}
	}
}

void down(){
	char c = 0;
	for (;; y += 4) {
		if (y == 640)
			up();
		setcolor(YELLOW);
		setfillcolor(GREEN);
		fillcircle(x, y, 10);
		Sleep(1);
		setcolor(BLACK);
		setfillcolor(BLACK);
		fillcircle(x, y, 10);

		if (_kbhit())
			c = _getch();
		switch (c) {
		case 'a': left(); break;
		case 'd': right(); break;
		case 'w': up(); break;
		case 's': down(); break;
		case 27: exit(0);
		}
	}
}

int main()
{
	initgraph(640, 640); 
	
	setcolor(YELLOW);
	setfillcolor(GREEN);
	fillcircle(x, y, 10);
	char c = 0;
	//if (_kbhit())
	c = _getch();
	switch (c) {
		case 'a': left(); break;
		case 'd': right(); break;
		case 'w': up(); break;
		case 's': down(); break;
		case 27: exit(0);
	}
	return 0;
}